<?php

set_time_limit(600);

/*
** An useless script, but very funny :-)
*/

define('DIR', './images/');
define('XNUM', 10);

$dir = opendir(DIR);
$number = 0;
if (!$dir)
    die("Go to hell!\n");
while (readdir($dir))
    $number++;
$number -= 2;
closedir($dir);

$width = 125 * XNUM;
$height = (($number / XNUM) * 170);

$bigimage = imagecreatetruecolor($width, $height);

if (!$bigimage)
    die("To low am I\n");

imagefill($bigimage, 0, 0, imagecolorallocate($bigimage, 255, 255, 255));

$dir = opendir(DIR);
if (!$dir)
    die("Go to hell!\n");

$x = 0;
$y = 0;

$count = 0;

while (($item = readdir($dir)))
{
   if ($item[0] != "." && $item != "index.html")
   {
	$image = imagecreatefrompng(DIR . $item);
	if ($image)
	{
		$count++;
		imagecopy($bigimage, $image, $x * 125, $y * 170, 0, 0, 125, 170);
		echo "Generated $item [$count / $number]\n";
		$x++;
		if ($x == XNUM)
		{
			$x = 0;
			$y++;
		}
	}
   }
}

imagepng($bigimage, "wall/big_image" . time() . ".jpg");
closedir($dir);

?>
